package cn.wolfcode.advice;

import org.apache.shiro.authz.AuthorizationException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * @author jishushen
 * @create 2021-02-20 12:57
 * 统一的异常处理
 */
@ControllerAdvice
public class MyExceptionAdvice {

    @ExceptionHandler(AuthorizationException.class)
    public String authorization(){
        //捕获到全局的 没有权限的异常
        return "redirect:/error/unauthorized.do";
    }

    @ExceptionHandler(RuntimeException.class)
    public String runtimeException(){
        //捕获到运行时的异常，我们把它打印出来，便于调试，转到错误的controller,给前端一个友好页面
        return "redirect:/error/error.do";
    }
}
